﻿
namespace System.Erp.Runtime
{
    /// <summary>
    /// 创建一个服务实现的零件
    /// </summary>
    public class ServicePart : PartBase
    {
        /// <summary>
        /// 创建 ServicePart 实例。
        /// </summary>
        /// <param name="workspace">工作区</param>
        /// <param name="interfaceType">接口的类型</param>
        /// <param name="serviceType">服务实现的类型</param>
        /// <param name="creatorAtt">创建者定义</param>
        public ServicePart(Workspace workspace,Type interfaceType,Type serviceType,CreatorAttribute creatorAtt)
            :base(workspace)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }
            if (creatorAtt == null)
            {
                throw new ArgumentNullException("creatorAtt");
            }

            this._interfaceType = interfaceType;
            this._serviceType = serviceType;
            this._creatorAtt = creatorAtt;
        }
        
        /// <summary>
        /// 返回服务实现的识别名称。
        /// </summary>
        /// <returns>唯一的识别名称，使用Service(interface;serviceType)格式。</returns>
        protected override string CreateName()
        {
            return "Service(" +
                   AttributeReflectedSource.GetTypeIdentity(this._interfaceType) +
                   ";" +
                   AttributeReflectedSource.GetTypeIdentity(this._serviceType) +
                   ")";
        }

        private readonly Type _interfaceType;
        /// <summary>
        /// 返回接口的类型
        /// </summary>
        public Type InterfaceType
        {
            get { return _interfaceType; }
        }

        private readonly Type _serviceType;
        /// <summary>
        /// 返回服务实现的类型
        /// </summary>
        public Type ServiceType
        {
            get { return _serviceType; }
        }

        private readonly CreatorAttribute _creatorAtt;
        /// <summary>
        /// 返回服务实现的创建者定义
        /// </summary>
        public CreatorAttribute CreatorAttribute
        {
            get { return _creatorAtt; }
        }
    }
}
